<template>
	<view class="art">
		<view class="author">
			<input class="uni-input" confirm-type="search" v-model="fileAuthor" placeholder="请编写作者" />
		</view>
		
		<view class="title">
			<input class="uni-input" confirm-type="search" v-model="fileTitle" placeholder="请编写您的文章标题" />
		</view>
		<view class="content"> 
			<!-- <cu-editor ref="editor" :url="uploadUrl" :header="header" :content="content" @before="onUploadBefore" @update="onUpdate" @save="onSave"></cu-editor> -->
			<input class="uni-input" confirm-type="search" v-model="fileContents" placeholder="请编写您的文章内容" />
		</view>
           <view @tap="uploadImg" class="login_from_input">
				<image  :src="fileFile"  mode="fileFile" class="box"></image>
			</view>
		<view class="up">
			<button size="mini" type="primary" @click="getNews" plain>提交</button>
		</view>
	</view>
</template>

<script>
	// import cuEditor from '@/components/cu-editor/cu-editor'
	export default {
		components:{
			// cuEditor
		},
		data() {
			return {
				fileAuthor :'',
				content:'',
				fileTitle: '',
				fileContents: '',
				fileFile: '',
				datas: [],
			}
		},
		methods: {
			getNews(){
				console.log(this.con)
				uni.request({
				    url: `http://localhost:7000/bbs/bbs/insertBbsArticle/`, //接口地址。
					data:{
						userId:2,
						userName:'思思',
						fileAuthor:this.fileAuthor,
						fileTitle:this.fileTitle,
						fileContents:this.fileContents,
						fileFile:this.fileFile,
					},
					method:'POST',
				    success: (res) => {
				        console.log(res)
				    }
				});
			},
			getContents(html){
				console.log(html)
			},
		uploadImg(){
				    uni.chooseImage({
				        count: 1, //默认9
				        sizeType: ['original'], //可以指定是原图还是压缩图，默认二者都有
				        sourceType: ['album'], //从相册选择
				        success:res => {
				            this.imgSrc=res.tempFilePaths[0]
				            //上传给后台
				            uni.uploadFile({
				                url:`http://localhost:7000/bbs/bbs/updateFile`,
				                filePath: res.tempFilePaths[0],
								name: 'file',
				                header: {
				                    'Authorization': "hello"
				                },
				                success: (uploadFileRes) => {
									console.log(uploadFileRes.data)
				                    this.fileFile=uploadFileRes.data
				                }
				            })
				        }	
				    });
				}, 
			}
	
	}
</script>

<style lang="scss">
	.art{
		.uni-input{
			margin-bottom: 30rpx;
		}
		// display: flex;
		margin: 30rpx;
		.content{
			height: 30rpx;
			margin-bottom: 30rpx;
		}
		.up{
			margin-top: 50rpx;
			height: 50rpx;
			width: 500rpx;
		}
	}
</style>
